package com.timschimandle.getitdone;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TaskFragment extends Fragment {
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		
		View v = inflater.inflate(R.layout.task_item, container,false);
		Bundle bundle = this.getArguments();
		
		LinearLayout ll = (LinearLayout) v.findViewById(R.id.frequency);
		LinearLayout frequency = (LinearLayout) inflater.inflate(R.layout.frequency_picker, null);
		ll.addView(frequency);
		
		if (bundle != null) {
							
			Task t = (Task) bundle.getSerializable("selected_task");
			
			EditText et = (EditText) v.findViewById(R.id.task_title);
			et.setText(t.getTitle());
			
			TextView tvd = (TextView) v.findViewById(R.id.day_number);
			tvd.setText(Integer.toString(t.getDatePart(0)));
			
			TextView tvm = (TextView) v.findViewById(R.id.month_number);
			tvm.setText(Integer.toString(t.getDatePart(1)));
			
			TextView tvy = (TextView) v.findViewById(R.id.year_number);
			tvy.setText(Integer.toString(t.getDatePart(2)));
			
			//need a call to set the spinner to the selected assignee.
			
			CheckBox cb = (CheckBox) v.findViewById(R.id.is_active);
			cb.setChecked((t.getActive() == 1));
				
		}
		
		return v;
		
	}
}
